package com.nlscan.qdkit.common.core.util

import android.content.pm.PackageManager
import com.nlscan.qdkit.common.core.util.Utils

/**
 * <pre>
 *  author: lin.qing
 *  time  : 2023/3/31
 *  desc  : AppUtils 扩展方法
 * </pre>
 *
 */
object AppExUtils {

    fun isAppPlatform(signLevelPermName: String?): Boolean {
        val pkgName = Utils.getApp().packageName
        return isAppPlatform(pkgName, signLevelPermName)
    }

    /**
     * 判断应用是否有平台签名
     * Return whether it is a platform application.
     *
     * @param signLevelPermName 需要在 AndroidManifest中声明的 signature permission，
     * e.g android.permission.BLUETOOTH_PRIVILEGED （即需要传入 protectionLevel="signature“ 的权限）
     * @return {@code true}: yes<br>{@code false}: no
     */
    fun isAppPlatform(pkgName: String?, signLevelPermName: String?): Boolean {
        return if (pkgName.isNullOrEmpty() || signLevelPermName.isNullOrEmpty()) {
            false
        } else {
            Utils.getApp().packageManager.checkPermission(
                signLevelPermName,
                pkgName
            ) == PackageManager.PERMISSION_GRANTED
        }
    }
}